package com.jz.community.modulemine.message.presenter;

import com.jz.community.basecomm.bean.BaseResponseInfo;
import com.jz.community.basecomm.mvp.BaseLifeCyclePresent;
import com.jz.community.basecomm.net.rxandroid.OnLoadListener;
import com.jz.community.modulemine.message.bean.MessageListBean;
import com.jz.community.modulemine.message.model.MessageModel;
import com.jz.community.modulemine.message.model.MessageModelImp;
import com.jz.community.modulemine.message.ui.MessageView;

public class MessagePresenter extends BaseLifeCyclePresent<MessageView.View> implements MessageView.Presenter {

    private MessageView.View view;
    private MessageModel messageModel;

    public MessagePresenter(MessageView.View view) {
        this.view = view;
        this.messageModel = new MessageModelImp(view.getContext());
    }

    @Override
    public void initMessageData(int page, int size) {
        messageModel.initMessageData(page, size, new OnLoadListener<MessageListBean>() {
            @Override
            public void onSuccess(MessageListBean messageListBean) {
                view.setMessageData(messageListBean);
            }

            @Override
            public void onFail(String msg, int code) {
                view.setMessageError(msg);

            }
        });

    }

    @Override
    public void readMessage(String id, int clickPosition) {
        messageModel.readMessage(id, new OnLoadListener<Boolean>() {
            @Override
            public void onSuccess(Boolean baseResponseInfo) {
                view.readMessageSuccess(clickPosition);
            }

            @Override
            public void onFail(String msg, int code) {
                view.readMessageError(msg);

            }
        });
    }
}
